package cn.xfdzx.android.apps.shop.adapter.remake;

import android.annotation.SuppressLint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.android.flexbox.AlignSelf;
import com.google.android.flexbox.FlexboxLayoutManager;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.DissatisfiedReasonBean;
import cn.xfdzx.android.apps.shop.bean.OrderDetailInfoBeen;

/**
 * Creator: zf.
 * Date: 2020/9/9.
 * Description:订单对骑手不满意原因适配器.
 */
public class OrderDissatisfiedReasonAdapter extends BaseQuickAdapter<DissatisfiedReasonBean.DataBean, BaseViewHolder>  {
    private OnItemOnClickListener onItemOnClickListener;
    private List<DissatisfiedReasonBean.DataBean> processinfo = new ArrayList<>();//商品列表
    private String type = "0";//0-零售1-批发
    public OrderDissatisfiedReasonAdapter(@Nullable List<DissatisfiedReasonBean.DataBean> data) {
        super(R.layout.item_dissatified, data);
        this.processinfo = data;
    }

    @Override
    public void setData(int index, @NonNull DissatisfiedReasonBean.DataBean data) {
        super.setData(index, data);
    }


    @SuppressLint("WrongConstant")
    @Override
    protected void convert(final BaseViewHolder viewHolder, final DissatisfiedReasonBean.DataBean date) {
        TextView tv_title = viewHolder.getView(R.id.tv_title);

        ViewGroup.LayoutParams params = tv_title.getLayoutParams();
        if (params instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) tv_title.getLayoutParams();
            flexboxLp.setFlexGrow(1.0f);
        }

        if (date.isCheck()){
            tv_title.setBackgroundResource(R.drawable.dfdf4d8_r5);
            tv_title.setTextColor(mContext.getResources().getColor(R.color.color_FB9129));
        }else {
            tv_title.setBackgroundResource(R.drawable.df5f5f6_r5);
            tv_title.setTextColor(mContext.getResources().getColor(R.color.color_787878));
        }
        viewHolder.setText(R.id.tv_title,date.getTitle());

        tv_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (date.isCheck()){
                    date.setCheck(false);
                    tv_title.setBackgroundResource(R.drawable.df5f5f6_r5);
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.color_787878));
                }else {
                    date.setCheck(true);
                    tv_title.setBackgroundResource(R.drawable.dfdf4d8_r5);
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.color_FB9129));
                }
                onItemOnClickListener.onItemOnClick(viewHolder.getLayoutPosition(),date);
            }
        });


    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<DissatisfiedReasonBean.DataBean> list){
        this.processinfo = list;
        super.replaceData(list);
    }

    public void setItemClickListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemOnClick(int position, DissatisfiedReasonBean.DataBean date);
    }

}
